#include "ccnodeext.h"
#include "qdebug.h"
CCNodeExt::CCNodeExt()
{
    
    
}

bool CCNodeExt::init()
{
    this->setContentSize(CCSizeMake(100,100));
    this->setPosition(100,100);
    
  
    this->setIsTouchEnabled(true);
    return true;
}


void CCNodeExt::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	qDebug() << "ccTouchesBegan";
	CCTouch * touch = (CCTouch*)pTouches->anyObject();
	CCPoint p = touch->locationInView(0);
	p = CCDirector::sharedDirector()->convertToGL(p);

	CCRect rect = boundingBox();
	qDebug() << rect.origin.x <<"," <<rect.origin.y << " ," <<rect.size.width <<"," <<rect.size.height;
	if (CCRect::CCRectContainsPoint(boundingBox(),p ) )
	{
		qDebug()<< "selected";
	}else
	{
		qDebug()<< "unselected";
	}
}

void CCNodeExt::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    
}

void CCNodeExt::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    
}

void CCNodeExt::draw()
{
    CCSize s = m_tContentSize;
    CCPoint vertices[4] = {
        ccp(0,0), ccp(s.width,0),
        ccp(s.width,s.height), ccp(0,s.height)
    };
    ccDrawPoly(vertices, 4, true);
}

